package com.xb.testdown.update.http;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * RetrofitServiceFactory： Retrofit 创建的工厂类
 */
public class RetrofitServiceFactory {

    public static <T> T createServiceFrom(final Class<T> serviceClass, String endpoint) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(endpoint)
                .addConverterFactory(GsonConverterFactory.create()) // 添加 gson 转换器，默认将服务端返回的数据转化为 jAVABean 对象
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // RxJava2 的适配暂时未用到
                .build();
        return retrofit.create(serviceClass);
    }

    public Retrofit getRetrofit() {
        retrofit2.Retrofit retrofit = new Retrofit.Builder().baseUrl("").addConverterFactory(GsonConverterFactory.create()).build();

        return retrofit;
    }
}
